package com.jrx.anytxn.transaction.controller.cms;

import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import com.jrx.anytxn.transaction.dto.manuallyTransaction.AdjustAmountReq;
import com.jrx.anytxn.transaction.dto.manuallyTransaction.LoanOrderRes;
import com.jrx.anytxn.transaction.handler.IManuallyTransactionHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jrx.auth.filter.service.InfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 手工交易录入
 *
 * @author : zhenghaopu
 * 2020/1/16
 */
@Api(tags = "手工交易")
@RestController
@RequestMapping("/transaction/manuallyTransactionEntry")
public class ManuallyTransactionController {

    private static final Logger logger = LoggerFactory.getLogger(ManuallyTransactionController.class);

    @Autowired
    private IManuallyTransactionHandler manuallyTransactionHandler;

    @Resource
    private InfoService infoService;


    @ApiOperation("手工交易订单列表")
    @GetMapping("/getOrderList")
    public TxnRespResult<ArrayList<LoanOrderRes>> getOrderList(@RequestParam String queryType,
                                                               @RequestParam String queryParam) throws TxnException {
        TxnRespResult<ArrayList<LoanOrderRes>> result = new TxnRespResult<>();
        String tenantId = String.valueOf(infoService.getUser().getProjectId());
        result.getSuccess((ArrayList<LoanOrderRes>) manuallyTransactionHandler.getOrderList(tenantId, queryType, queryParam));
        return result;
    }

    @ApiOperation("手工交易账户调整")
    @PostMapping("/adjustAccount")
    public TxnRespResult adjustAmount(@RequestBody AdjustAmountReq adjustAmountReq) throws TxnException {
        TxnRespResult result = new TxnRespResult<>();
        String tenantId = String.valueOf(infoService.getUser().getProjectId());
        String userId = String.valueOf(infoService.getUser().getUserName());
        manuallyTransactionHandler.adjustAmount(adjustAmountReq,tenantId,userId);
        result.getSuccess(null);
        return result;
    }

}
